﻿package mortal.game.view.vip.panel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class VipFirstRechargeWin extends Window
    {
        private var _picList:Vector.<GImageBitmap>;
        private var _itemList:Array;
        private var _vipItemConFig:TVip;
        private var _bg:GImageBitmap;
        private var _wumen:GImageBitmap;
        private var _vipTxt:GBitmap;
        private var _vipLevelBg:GImageBitmap;
        private var _vipTitle:GBitmap;
        private var _vipProgress:BaseProgressBar;
        private var _vipLevel:BitmapNumberText;
        private var _levelUpNeedMoney:GTextFiled;
        private var _rechargeBtn:GLoadingButton;
        private static var _instance:VipFirstRechargeWin;

        public function VipFirstRechargeWin(param1:ILayer = null)
        {
            this._picList = new Vector.<GImageBitmap>;
            this._itemList = new Array();
            this.setSize(760, 470);
            if (_instance != null)
            {
                throw new Error(" VipFirstRechargeWin 单例 ");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._vipItemConFig = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeItemWelfare);
            this._bg = UIFactory.gImageBitmap("", 0, 0, null);
            this.addChildAt(this._bg, 0);
            LoaderHelp.setBitmapdata("VipFirstRecahrgeBg.swf", this._bg);
            this._vipTitle = UIFactory.gBitmap("", 215, -130, this);
            this._vipLevelBg = UIFactory.gImageBitmap("", 105, 10, null);
            LoaderHelp.setBitmapdata("VipBg.swf", this._vipLevelBg);
            this._wumen = UIFactory.gImageBitmap("", -130, 0, this);
            LoaderHelp.setBitmapdata("ChallengPassBgWumen.swf", this._wumen);
            this._vipTxt = UIFactory.gBitmap("", 283, 240, this);
            this._vipLevel = UIFactory.bitmapNumberText(140, 37, "VipLevelTitle.png", 48.2, 50, -6, null);
            this._vipProgress = UICompomentPool.getUICompoment(BaseProgressBar);
            this._vipProgress.setBg(ImagesConst.VipProgressBg, false, 320, 30);
            this._vipProgress.setProgress(ImagesConst.VipProgress, false, 21, 8, 275, 14);
            this._vipProgress.setLabel(BaseProgressBar.ProgressBarTextNumber, 125, 5, 75, 8);
            this._vipProgress.x = 255;
            this._vipProgress.y = 48;
            addChild(this._vipProgress);
            this._levelUpNeedMoney = UIFactory.gTextField("", 330, 75, 300, 20, this);
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.VipReCharge, 595, 41, 156, 39, this);
            this._rechargeBtn.label = Language.getString(35586);
            this._rechargeBtn.drawNow();
            this.createItemList();
            this.createVipPic();
            this.updateReChargeAmount();
            this.updeteVipLevel();
            this.updatePicList();
            this.updateItemList();
            LoaderHelp.addResCallBack(ResFileConst.vipFirstRecharge, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._vipLevel.dispose(param1);
            this._vipLevel = null;
            this._vipLevelBg.dispose(param1);
            this._vipLevelBg = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._wumen.dispose(param1);
            this._wumen = null;
            this._vipTxt.dispose(param1);
            this._vipTxt = null;
            this._vipProgress.dispose(param1);
            this._vipProgress = null;
            this._levelUpNeedMoney.dispose(param1);
            this._levelUpNeedMoney = null;
            this._vipTitle.dispose(param1);
            this._vipTitle = null;
            this._itemList.length = 0;
            this._picList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._vipTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.VipTitle);
            addChild(this._vipLevelBg);
            addChild(this._vipLevel);
            this._vipTxt.bitmapData = GlobalClass.getBitmapData(ImagesConst.VipFirstReChargeTxt);
            return;
        }// end function

        private function createItemList() : void
        {
            var _loc_1:BaseItem = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < 8)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(BaseItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                _loc_1.x = int(_loc_3 / 4) * 110 + _loc_3 * 45 + 192;
                _loc_1.y = 167;
                _loc_1.isDragAble = false;
                _loc_1.isDropAble = false;
                this.addChild(_loc_1);
                this.pushUIToDisposeVec(_loc_1);
                if (_loc_3 < 4)
                {
                    _loc_2 = (3 - _loc_3) * 2;
                }
                else
                {
                    _loc_2 = (_loc_3 - 3) * 2 - 1;
                }
                this._itemList[_loc_2] = _loc_1;
                _loc_3++;
            }
            return;
        }// end function

        private function createVipPic() : void
        {
            var _loc_1:int = 0;
            var _loc_2:GImageBitmap = null;
            while (_loc_1 < 4)
            {
                
                _loc_2 = UIFactory.gImageBitmap(null);
                _loc_2.x = _loc_1 % 2 * 250 + 188;
                _loc_2.y = int(_loc_1 / 2) * 85 + 280;
                this.addChild(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                this._picList.push(_loc_2);
                _loc_1++;
            }
            return;
        }// end function

        private function updateReChargeTxt() : void
        {
            if (Cache.instance.vip.level == 10)
            {
                this._levelUpNeedMoney.text = Language.getString(35587);
            }
            else if (Cache.instance.vip.level == -1)
            {
                this._levelUpNeedMoney.htmlText = Language.getStringByParam(30707, VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level) - Cache.instance.vip.reChargeMoney, "1");
            }
            else
            {
                this._levelUpNeedMoney.htmlText = Language.getStringByParam(30703, VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level) - Cache.instance.vip.reChargeMoney, (Cache.instance.vip.level + 1));
            }
            return;
        }// end function

        private function updateItemList() : void
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_1:* = ItemConfig.instance.getConfig(int(this._vipItemConFig.desc)) as ItemGiftBagInfo;
            var _loc_2:* = _loc_1.itemList1.split("&");
            while (_loc_4 < this._itemList.length)
            {
                
                if (_loc_4 > (_loc_2.length - 1))
                {
                    this._itemList[_loc_4].itemData = null;
                }
                else
                {
                    _loc_3 = _loc_2[_loc_4].split("#");
                    this._itemList[_loc_4].itemData = new ItemData(int(_loc_3[1]));
                    (this._itemList[_loc_4] as BaseItem).amount = _loc_3[0];
                }
                _loc_4++;
            }
            return;
        }// end function

        private function updatePicList() : void
        {
            var _loc_3:int = 0;
            var _loc_1:* = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeImgDesc);
            var _loc_2:* = _loc_1.desc.split("#");
            while (_loc_3 < _loc_2.length)
            {
                
                LoaderHelp.setBitmapdata(_loc_2[_loc_3] + ".swf", this._picList[_loc_3]);
                _loc_3++;
            }
            return;
        }// end function

        public function updeteVipLevel(param1:Object = null) : void
        {
            this._vipLevel.text = VipUtil.vipLevel.toString();
            this.updateReChargeTxt();
            return;
        }// end function

        public function updateReChargeAmount(event:DataEvent = null) : void
        {
            var _loc_2:* = Cache.instance.vip.reChargeMoney;
            var _loc_3:* = VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level);
            this._vipProgress.setValue(_loc_2 > _loc_3 ? (_loc_3) : (_loc_2), _loc_3);
            this.updateReChargeTxt();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.updeteVipLevel);
            NetDispatcher.addCmdListener(ServerCommand.ReChargeMoney, this.updateReChargeAmount);
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.updeteVipLevel);
            NetDispatcher.removeCmdListener(ServerCommand.ReChargeMoney, this.updateReChargeAmount);
            return;
        }// end function

        public static function get instance() : VipFirstRechargeWin
        {
            if (_instance == null)
            {
                _instance = new VipFirstRechargeWin;
            }
            return _instance;
        }// end function

    }
}
